package com.crc64.program;

import java.util.Arrays;
import java.util.Scanner;

import com.crc64.comm.serialcomm.DataBit;
import com.crc64.comm.serialcomm.DataRate;
import com.crc64.comm.serialcomm.Parity;
import com.crc64.comm.serialcomm.SerialComm;
import com.crc64.comm.serialcomm.StopBit;

public class Driver {

	public static void main(String[] args) throws Exception {
		byte[] rxMessage = new byte[11];
		SerialComm serialConnection = new SerialComm("/dev/ttyUSB0", DataRate.DATA_RATE_4800, DataBit.DATA_BITS_8, StopBit.STOP_BIT_1, Parity.PARITY_NONE, rxMessage);
		serialConnection.addSerialCommListener(new SerialComm.SerialCommListener() {
			@Override
			public void newMessageReceived(byte[] message) {
				System.out.println(Arrays.toString(message));
			}
		});
		serialConnection.open();
		try (Scanner scanner = new Scanner(System.in)) {
			String line;
			do {
				line = scanner.nextLine().toLowerCase();
			} while (!line.equals("q"));
			serialConnection.close();
		}
	}
}
